﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 工作日定义
    /// </summary>
    public class WorkCalendar
    {
        /// <summary>
        /// 工作日定义DAL
        /// </summary>
        private readonly DAL.WorkCalendar dal = new DAL.WorkCalendar();
        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="strWhere">查询数据列表</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="workDate"></param>
        /// <returns></returns>
        public DataSet GetWorkDay(string workDate)
        {
            return dal.GetWorkDay(workDate);
        }

        /// <summary>
        /// 工作日定义保存方法
        /// </summary>
        /// <param name="fEntityNo">公司编号</param>
        /// <param name="fWorkDate">所修改或增加的年份</param>
        /// <param name="workCalendarList">修改或增加的数据集合</param>
        public void ADDFWorkDate(string fEntityNo, string fWorkDate, List<Model.WorkCalendar> workCalendarList)
        {
            dal.ADDFWorkDate(fEntityNo, fWorkDate, workCalendarList);
        }

        /// <summary>
        /// 更具开始时间和结束时间获取数据列表
        /// </summary>
        /// <param name="begindate">开始时间</param>
        /// <param name="enddate">结束时间</param>
        /// <returns>DataSet对象</returns>
        public List<Model.WorkCalendar> GetLeaveStatisticsList(string begindate, string enddate)
        {
            DataSet ds = dal.GetLeaveStatisticsList(begindate, enddate);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        /// <param name="strWhere">查询数据列表</param>
        /// <returns>List对象</returns>
        public List<Model.WorkCalendar> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// DataSet转换List
        /// </summary>
        /// <param name="dt">DataSet对象</param>
        /// <returns>List对象</returns>
        public List<Model.WorkCalendar> DataTableToList(DataTable dt)
        {
            List<Model.WorkCalendar> modelList = new List<Model.WorkCalendar>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.WorkCalendar model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.WorkCalendar();
                    model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    if (dt.Rows[n]["FWorkDate"].ToString() != "")
                    {
                        model.FWorkDate = DateTime.Parse(dt.Rows[n]["FWorkDate"].ToString());
                    }
                    model.FNote = dt.Rows[n]["FNote"].ToString();
                    model.Fdeftype = dt.Rows[n]["Fdeftype"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }
    }
}
